package com.tjec.project.system.controller;

import java.util.List;
import java.util.stream.Collectors;

import com.tjec.framework.web.domain.TreeSelect;
import com.tjec.project.system.domain.BmsMdArea;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.system.domain.BmsMdIndustryCategory;
import com.tjec.project.system.service.IBmsMdIndustryCategoryService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 行业类别Controller
 * 
 * @author cjj
 * @date 2020-06-24
 */
@RestController
@RequestMapping("/system/industryCategory")
public class BmsMdIndustryCategoryController extends BaseController
{
    @Autowired
    private IBmsMdIndustryCategoryService bmsMdIndustryCategoryService;

    /**
     * 省市区树（二层结构）
     */
    @GetMapping("/treeTwo")
    @ApiOperation("行业类别树")
    public AjaxResult tree(BmsMdIndustryCategory bmsMdIndustryCategory)
    {
        List<BmsMdIndustryCategory> list = bmsMdIndustryCategoryService.selectBmsMdIndustryCategoryListTwo(bmsMdIndustryCategory);
        return AjaxResult.success(bmsMdIndustryCategoryService.buildBmsMdIndustryCategorySelect(list));
    }


    /**
     * 查询行业类别列表
     */
//    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsMdIndustryCategory bmsMdIndustryCategory)
    {
        startPage();
        List<BmsMdIndustryCategory> list = bmsMdIndustryCategoryService.selectBmsMdIndustryCategoryList(bmsMdIndustryCategory);
        return getDataTable(list);
    }

    /**
     * 导出行业类别列表
     */
//    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "行业类别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsMdIndustryCategory bmsMdIndustryCategory)
    {
        List<BmsMdIndustryCategory> list = bmsMdIndustryCategoryService.selectBmsMdIndustryCategoryList(bmsMdIndustryCategory);
        ExcelUtil<BmsMdIndustryCategory> util = new ExcelUtil<BmsMdIndustryCategory>(BmsMdIndustryCategory.class);
        return util.exportExcel(list, "category");
    }

    /**
     * 获取行业类别详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsMdIndustryCategoryService.selectBmsMdIndustryCategoryByGuid(guid));
    }

    /**
     * 新增行业类别
     */
//    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "行业类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsMdIndustryCategory bmsMdIndustryCategory)
    {
        return toAjax(bmsMdIndustryCategoryService.insertBmsMdIndustryCategory(bmsMdIndustryCategory));
    }

    /**
     * 修改行业类别
     */
//    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "行业类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsMdIndustryCategory bmsMdIndustryCategory)
    {
        return toAjax(bmsMdIndustryCategoryService.updateBmsMdIndustryCategory(bmsMdIndustryCategory));
    }

    /**
     * 删除行业类别
     */
//    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "行业类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(bmsMdIndustryCategoryService.deleteBmsMdIndustryCategoryByGuids(guids));
    }
}
